package test;


import sjjg.graph.Edge;
import sjjg.graph.EdgeWeightGraph;
import sjjg.graph.KruskalMST;
import sjjg.graph.PrimMST;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class MinCreatTreeTest_Kruskal {
    public static void main(String[] args)throws Exception {
        //获得字符输入流 从文件中读取数据
        BufferedReader br=new BufferedReader(new InputStreamReader(MinCreatTreeTest_Kruskal.class.getClassLoader().getResourceAsStream("min_create_tree_test.txt")));
        //初始化加权无向图
        int V = Integer.parseInt(br.readLine());
        EdgeWeightGraph weightGraph=new EdgeWeightGraph(V);
        //获得边总数
        Integer.parseInt(br.readLine());
        //添加边
        String s;
        while ((s=br.readLine())!=null){
            String[] split = s.split(" ");
             int v=Integer.parseInt(split[0]);
            int w=Integer.parseInt(split[1]);
            Double weight=Double.parseDouble(split[2]);
            Edge edge = new Edge(v, w, weight);
            weightGraph.addEdge(edge);
        }
        //生成最小生成树
        KruskalMST kruskalMST=new KruskalMST(weightGraph);
        //遍历最小生成树
        for (Edge edge : kruskalMST.edges()) {
            System.out.println(edge.either()+"<->"+edge.another(edge.either())+ "->"+edge.weight());
        }
    }
}
